Skip to content

feat: add configurable JWT secret, anonymous authentication and standardize rust practices#1

Open
vihu wants to merge 2 commits intoKayleexx:mainfrom
vihu:rg/standardize-with-anonymous-auth
Open

feat: add configurable JWT secret, anonymous authentication and standardize rust practices#1
vihu wants to merge 2 commits intoKayleexx:mainfrom
vihu:rg/standardize-with-anonymous-auth

Conversation

@vihu
Copy link

@vihu vihu commented Dec 9, 2025

Hello!

Firstly, thank you for starting this project and secondly I apologize for the large diff here.

Basically the changes in this branch are to bring the project upto some sort of production-ready standardization along with an introduction of anonymous mode for potentially hosting the server somewhere. That said, below is the full rundown of the most critical changes.

Summary

  • Add JWT authentication with configurable secrets via environment variables
  • Introduce optional anonymous authentication mode for clients to generate their own tokens
  • Add CLI improvements via clap and workspace dependency consolidation

Changes

Authentication (conflux/src/auth.rs)

  • Add JWT_SECRET static via LazyLock loading from CONFLUX_JWT_SECRET env var
  • Panic in release mode if CONFLUX_JWT_SECRET is not set; use dev default in debug mode
  • Add validate_token_anonymous() function that validates JWT structure without signature verification
  • Add 12 unit tests covering validation, expiry, future-dated tokens, wrong secrets, and signature bypass

Server (conflux/src/server.rs)

  • Add anonymous_mode: bool field to AppState
  • Route token validation conditionally based on mode

CLI (confluxd/src/main.rs)

  • Migrate to clap with derive macros
  • Add --port, --host, --anonymous, --idle-timeout arguments

Infrastructure

  • Consolidate dependencies to workspace level
  • Add rust-toolchain.toml and .github/workflows/rust.yml

Usage

# Production (requires CONFLUX_JWT_SECRET)
CONFLUX_JWT_SECRET=your-secret-here cargo run -p confluxd

# Anonymous mode (clients can self-sign tokens)
cargo run -p confluxd -- --anonymous

Breaking Changes

Production deployments must set CONFLUX_JWT_SECRET: Release builds will panic on startup if the environment variable is not set.

vihu added 2 commits December 9, 2025 21:25
…mode

Add production-ready JWT configuration with environment variable support and an optional anonymous authentication mode for development/testing scenarios.

JWT Secret Configuration:
- Load CONFLUX_JWT_SECRET from environment via LazyLock
- Panic in release builds if secret is not set
- Use default dev secret in debug builds with warning

Anonymous Authentication Mode:
- Add validate_token_anonymous() that verifies JWT structure without signature verification, enabling client-generated tokens
- Add --anonymous CLI flag to enable this mode
- Add anonymous_mode field to AppState for conditional auth routing

CLI Enhancements:
- Migrate to clap with derive macros for argument parsing
- Add --port, --host, --anonymous, and --idle-timeout flags
- Emit warning when anonymous mode is enabled

Infrastructure:
- Consolidate dependencies to workspace level in root Cargo.toml
- Add rust-toolchain.toml pinning stable with clippy, rustfmt, rust-analyzer
- Add GitHub Actions CI workflow (fmt, clippy, build, test)

Includes 12 unit tests covering token generation, validation, expiry,
future-dated tokens, signature verification, and anonymous mode behavior.
- Fresh clients send an empty state vector when requesting initial sync. Previously this would fail during StateVector decoding. Now empty input is treated as "client has no state" and returns the full document.
- Add tests for empty, valid, and invalid state vector inputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant